You could create a simple password protected area using If/Else.
A PHP page with a conditional statement could be set up to process an HTML login form.
A variable “$password” could be set, and the Header command could be used to redirect on success or failure.
Your HTML page would be a simple form...
<form action="login.php" method="post">
<INPUT type="password" name="password">
<input type="submit">
</form>
This HTML form will set the variable in the “action” page (named login.php in this example) with the $_POST command (more on this later) and do one of two things:
- If the password is correct, it will show the desired content.
- If it is NOT correct, it will redirect to another URL (or page).
Since the action is in PHP, viewing the source in the web browser isn’t going to reveal the password.
...And your PHP “Action” page would be an If/Else combined with a Redirect...
<?php
if($_POST['password'] == 'some_password'){
echo “
<!---Put your protected HTML content here...-->
“ ;
} else {
header ("location: some_error_page.html");
}
?>
...And Voila! A simple way to password protect a page.
I wouldn’t use this for sensitive stuff (like putting your social security number online) but it’s good for a simple, single layer of security.
0 Comments
You’ll most likely want to use IF with ELSE. |
David Rentson
If this free PHP and MYSQL Tutorial is helpful for you... Great! Archives
October 2008
Categories
All
|